package com.orange.lockscreensettings.wallpaper;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.orange.lockscreensettings.R;

public class WallpaperPickerAdapter extends BaseAdapter {
	private final LayoutInflater	mInflater;

	private final List<ListItem>	mItems	= new ArrayList<ListItem>();

	// public static final int WALLPAPER_GALLERY = 0;
	// public static final int WALLPAPER_LOCKSCREEN = 1;

	public WallpaperPickerAdapter(Context context) {
		super();
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		// Create default actions
		Resources res = context.getResources();

		mItems.add(new ListItem(res, R.string.wallpaper_gallery,
				R.drawable.ic_launcher_gallery));
		mItems.add(new ListItem(res, R.string.wallpaper_lockscreen,
				R.drawable.ic_launcher_wallpaper));
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ListItem item = (ListItem) getItem(position);

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.dialog_wallpaper, parent,
					false);
		}

		TextView textView = (TextView) convertView;
		textView.setText(item.text);
		textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null,
				null, null);

		return convertView;
	}

	public int getCount() {
		return mItems.size();
	}

	public Object getItem(int position) {
		return mItems.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public class ListItem {
		private final CharSequence	text;
		private final Drawable		image;

		public ListItem(Resources res, int textResourceId, int imageResourceId) {
			text = res.getString(textResourceId);
			if (imageResourceId != -1) {
				image = res.getDrawable(imageResourceId);
			} else {
				image = null;
			}
		}
	}
}
